//
//  HCMineHeaderView.m
//  HappyChildren
//
//  Created by WillyZhao on 2016/12/26.
//  Copyright © 2016年 WillyZhao. All rights reserved.
//

#import "HCMineHeaderView.h"


@interface HCMineHeaderView () {
    UIView *headTapView;
}

@end

@implementation HCMineHeaderView

-(instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self layoutSubCustomViewFrame:frame];
    }
    return self;
}

-(void)layoutSubCustomViewFrame:(CGRect)frame {
    CGFloat w = frame.size.width;
    CGFloat h = frame.size.height;
    
    //添加分割线
    UIView *prompt_line = [[UIView alloc] initWithFrame:CGRectMake(0, YBKAdaptiveH(118), w, 1)];
    prompt_line.backgroundColor = YBKRGBCOLOR(241, 241, 241, 1);
    [self addSubview:prompt_line];
    
    //添加上部视图容器
    headTapView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, w, YBKAdaptiveH(118))];
    [self addSubview:headTapView];
    
    UIView *prompt_verticalOne = [[UIView alloc] initWithFrame:CGRectMake((w - 2)/3.0, prompt_line.frame.origin.y+prompt_line.frame.size.height, 1, h - 1 - YBKAdaptiveH(118))];
    prompt_verticalOne.backgroundColor = YBKRGBCOLOR(241, 241, 241, 1);
    [self addSubview:prompt_verticalOne];
    
    UIView *prompt_verticaltwo = [[UIView alloc] initWithFrame:CGRectMake(prompt_verticalOne.frame.origin.x+1+(w - 2)/3.0, prompt_line.frame.origin.y+prompt_line.frame.size.height, 1, h - 1 - YBKAdaptiveH(118))];
    prompt_verticaltwo.backgroundColor = YBKRGBCOLOR(241, 241, 241, 1);
    [self addSubview:prompt_verticaltwo];
    
    //添加头像
    self.headerIMG = [[UIImageView alloc] initWithFrame:CGRectMake(YBKAdaptiveW(20), YBKAdaptiveH(17), YBKAdaptiveW(83), YBKAdaptiveW(83))];
    self.headerIMG.layer.masksToBounds = YES;
    self.headerIMG.userInteractionEnabled = YES;
    self.headerIMG.layer.cornerRadius = YBKAdaptiveW(83)/2.0;
    self.headerIMG.contentMode = UIViewContentModeScaleAspectFill;
    [headTapView addSubview:self.headerIMG];
    
    //添加用户名称
    self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(YBKAdaptiveW(116), YBKAdaptiveH(36), 200, YBKAdaptiveH(20))];
    self.nameLabel.font = YBKSystemFont(YBKAdaptiveFont(20));
    self.nameLabel.textColor = YBKRGBCOLOR(102, 102, 102, 1);
    [headTapView addSubview:self.nameLabel];
    
    //VIP
    self.imageView_VIP = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"happy_mine_vip"]];
    self.imageView_VIP.frame = CGRectMake(YBKAdaptiveW(116), YBKAdaptiveH(66), YBKAdaptiveW(41), YBKAdaptiveH(18.5));
    [headTapView addSubview:self.imageView_VIP];
    
    //下一级图标
    UIImageView *imageView_next = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"happy_mine_next_header"]];
    imageView_next.frame = CGRectMake(YBKAdaptiveW(303), YBKAdaptiveW(48), YBKAdaptiveW(15), YBKAdaptiveH(28.5));
    [headTapView addSubview:imageView_next];
    
    //添加点击进入详情页方法
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(userInfoTap:)];
    [headTapView addGestureRecognizer:tap];
    
    /**
     添加余额，积分，优惠
     */
    
    //余额
    UILabel *label_money = [[UILabel alloc] initWithFrame:CGRectMake(((w - 2)/3.0 - YBKAdaptiveW(60))/2.0, YBKAdaptiveH(129), YBKAdaptiveW(60), YBKAdaptiveH(14))];
    label_money.textColor = [UIColor darkGrayColor];
    label_money.text = @"会员卡";
    label_money.font = YBKSystemFont(YBKAdaptiveFont(14));
    label_money.textAlignment = NSTextAlignmentCenter;
    [self addSubview:label_money];
    
    self.balanceLabel = [[WZLabel alloc] initWithFrame:CGRectMake(0, label_money.frame.origin.y+label_money.frame.size.height+YBKAdaptiveH(8), (w - 2)/3.0, 15)];
    self.balanceLabel.text = @"269867576675";
    self.balanceLabel.font = YBKSystemFont(YBKAdaptiveFont(12));
    self.balanceLabel.textAlignment = NSTextAlignmentCenter;
    self.balanceLabel.textColor = YBKRGBCOLOR(240, 96, 96, 1);
    [self addSubview:self.balanceLabel];
    [self.balanceLabel setFont:YBKSystemFont(YBKAdaptiveFont(8)) childrenString:@"元"];
    
    UIButton *moneyBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, YBKAdaptiveH(119), (w - 2)/3.0, YBKAdaptiveH((h - 118)) )];
    moneyBtn.tag = 1;
    [moneyBtn addTarget:self action:@selector(threeBtnActions:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:moneyBtn];
    
    //优惠
    UILabel *label_preferentialLabel = [[UILabel alloc] initWithFrame:CGRectMake(((w - 2)/3.0 - 35)/2.0+(w - 2)/3.0 +1, YBKAdaptiveH(129), YBKAdaptiveW(35), YBKAdaptiveH(14))];
    label_preferentialLabel.textColor = [UIColor darkGrayColor];
    label_preferentialLabel.text = @"优惠";
    label_preferentialLabel.font = YBKSystemFont(YBKAdaptiveFont(14));
    label_preferentialLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:label_preferentialLabel];
    
    self.preferentialLabel = [[WZLabel alloc] initWithFrame:CGRectMake(0+(w - 2)/3.0 +1, label_money.frame.origin.y+label_money.frame.size.height+YBKAdaptiveH(8), (w - 2)/3.0, 13)];
    self.preferentialLabel.text = @"2 个";
    self.preferentialLabel.font = YBKSystemFont(YBKAdaptiveFont(12));
    self.preferentialLabel.textAlignment = NSTextAlignmentCenter;
    self.preferentialLabel.textColor = YBKRGBCOLOR(240, 96, 96, 1);
    [self addSubview:self.preferentialLabel];
    [self.preferentialLabel setFont:YBKSystemFont(YBKAdaptiveFont(8)) childrenString:@"个"];
    
    UIButton *preferentialLabel = [[UIButton alloc] initWithFrame:CGRectMake((w - 2)/3.0 +1, YBKAdaptiveH(119), (w - 2)/3.0, YBKAdaptiveH((h - 118)) )];
    preferentialLabel.tag = 2;
    [preferentialLabel addTarget:self action:@selector(threeBtnActions:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:preferentialLabel];

    //积分
    UILabel *label_score = [[UILabel alloc] initWithFrame:CGRectMake(((w - 2)/3.0 - 35)/2.0+((w - 2)/3.0 +1)*2.0, YBKAdaptiveH(129), YBKAdaptiveW(35), YBKAdaptiveH(14))];
    label_score.textColor = [UIColor darkGrayColor];
    label_score.text = @"积分";
    label_score.font = YBKSystemFont(YBKAdaptiveFont(14));
    label_score.textAlignment = NSTextAlignmentCenter;
    [self addSubview:label_score];
    
    self.scoreLabel = [[WZLabel alloc] initWithFrame:CGRectMake((0+(w - 2)/3.0 +1)*2.0, label_money.frame.origin.y+label_money.frame.size.height+YBKAdaptiveH(8), (w - 2)/3.0, 13)];
    self.scoreLabel.text = @"1053 分";
    self.scoreLabel.font = YBKSystemFont(YBKAdaptiveFont(12));
    self.scoreLabel.textAlignment = NSTextAlignmentCenter;
    self.scoreLabel.textColor = YBKRGBCOLOR(240, 96, 96, 1);
    [self addSubview:self.scoreLabel];
    [self.scoreLabel setFont:YBKSystemFont(YBKAdaptiveFont(8)) childrenString:@"分"];
    
    UIButton *score = [[UIButton alloc] initWithFrame:CGRectMake(2*((w - 2)/3.0 +1), YBKAdaptiveH(119), (w - 2)/3.0, YBKAdaptiveH((h - 118)) )];
    score.tag = 3;
    [score addTarget:self action:@selector(threeBtnActions:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:score];

}

#pragma mark 余额，积分，优惠点击事件
-(void)threeBtnActions:(UIButton *)btn {
    if ([self.delegate respondsToSelector:@selector(hcMineHeaderViewClickedStyle:)]&&self.delegate) {
        if (btn.tag == 1) {
            [self.delegate hcMineHeaderViewClickedStyle:HCMineHeaderViewMoneyClicked];
        }else if (btn.tag == 2) {
            [self.delegate hcMineHeaderViewClickedStyle:HCMineHeaderViewPreferentialClicked];
        }else if (btn.tag == 3) {
            [self.delegate hcMineHeaderViewClickedStyle:HCMineHeaderViewScoreClicked];
        }
    }
}

#pragma mark 头像进入下级详情页
-(void)userInfoTap:(UITapGestureRecognizer *)tap {
    if ([self.delegate respondsToSelector:@selector(hcMineHeaderViewUserInfoClicked:)]&&self.delegate) {
        [self.delegate hcMineHeaderViewUserInfoClicked:self];
    }
}

@end
